<template>
    <div>
        <el-row :gutter="10" style="margin-bottom: 60px">
            <el-col :span="6">
                <el-card style="color: #409EFF">
                    <div><i class="el-icon-user-solid" /> 用户总数</div>
                    <div style="padding: 10px 0; text-align: center; font-weight: bold">
                        100
                    </div>
                </el-card>
            </el-col>
            <el-col :span="6">
                <el-card style="color: #F56C6C">
                    <div><i class="el-icon-money" /> 销售总量</div>
                    <div style="padding: 10px 0; text-align: center; font-weight: bold">
                        ￥ 1000000
                    </div>
                </el-card>
            </el-col>
            <el-col :span="6">
                <el-card style="color: #67C23A">
                    <div><i class="el-icon-bank-card" /> 收益总额</div>
                    <div style="padding: 10px 0; text-align: center; font-weight: bold">
                        ￥ 300000
                    </div>
                </el-card>
            </el-col>
            <el-col :span="6">
                <el-card style="color: #E6A23C">
                    <div><i class="el-icon-s-shop" /> 门店总数</div>
                    <div style="padding: 10px 0; text-align: center; font-weight: bold">
                        20
                    </div>
                </el-card>
            </el-col>
        </el-row>
        <el-row>
            <el-col :span="12">
                <div id="main" style="width: 500px; height: 600px;" ></div>
            </el-col>

            <el-col :span="12">
                <div id="pie" style="width: 500px; height: 600px;"></div>
            </el-col>
        </el-row>

    </div>
</template>

<script>
    import * as echarts from 'echarts'
    import request from "@/utils/request";
    export default {
        name: "Home",
        data() {
            return {

            }
        },
        mounted() {
            var option = {
                title: {
                    text: '各季度用户购买统计',
                    subtext: '趋势图',
                    left: 'center'
                },
                tooltip: {
                    trigger: 'item'
                },
                legend: {
                    orient: 'vertical',
                    left: 'left'
                },
                xAxis: {
                    type: 'category',
                    data: ['一月' ,'二月','三月' , '四月', '五月' , '六月' , '七月' , '八月', '九月','十月', '十一月','十二月']
                },
                yAxis: {
                    type: 'value'
                },
                series: [
                    {
                        name: "各季度用户购买统计",
                        data: [],
                        type: 'bar'
                    },
                    {
                        name: "各季度用户购买统计",
                        data: [],
                        type: 'line'
                    },
                ]
            };
            var pieOption = {
                title: {
                    text: '各季度用户购买统计',
                    subtext: '比例图',
                    left: 'center'
                },
                legend: {
                    top: 'bottom'
                },
                toolbox: {
                    show: true,
                    feature: {
                        mark: { show: true },
                        dataView: { show: true, readOnly: false },
                        restore: { show: true },
                        saveAsImage: { show: true }
                    }
                },
                series: [
                    {
                        name: 'Nightingale Chart',
                        type: 'pie',
                        radius: [40,200],
                        center: ['50%', '50%'],
                        roseType: 'area',
                        itemStyle: {
                            borderRadius: 12
                        },
                        data: [
                            // { value: 40, name: 'rose 1' },
                            // { value: 38, name: 'rose 2' },
                            // { value: 32, name: 'rose 3' },
                            // { value: 30, name: 'rose 4' },
                            // { value: 28, name: 'rose 5' },
                            // { value: 26, name: 'rose 6' },
                            // { value: 22, name: 'rose 7' },
                            // { value: 18, name: 'rose 8' }
                        ]
                    }
                ]
            };


            var chartDom = document.getElementById('main');
            var myChart = echarts.init(chartDom);

            var pieDom = document.getElementById('pie');
            var pieChart = echarts.init(pieDom);

            request.get("/echarts/members").then(res => {


                // 填空
                // option.xAxis.data = res.data.x
                option.series[0].data = res.data
                option.series[1].data = res.data
                // 数据准备完毕之后再set
                myChart.setOption(option);
                console.log(res)

                pieOption.series[0].data=
                    [
                        { value: res.data[0], name: '一月' },
                        { value: res.data[1], name: '二月' },
                        { value: res.data[2], name: '三月' },
                        { value: res.data[3], name: '四月' },
                        { value: res.data[4], name: '五月' },
                        { value: res.data[5], name: '六月' },
                        { value: res.data[6], name: '七月' },
                        { value: res.data[7], name: '八月' },
                        { value: res.data[8], name: '九月' },
                        { value: res.data[9], name: '十月' },
                        { value: res.data[10], name: '十一月' },
                        { value: res.data[11], name: '十二月' }
                    ]
                pieChart.setOption(pieOption)
            })
        }
    }
</script>

<style scoped>

</style>
